#pragma once
#include <iostream>
#include <unistd.h>
#include <cstdlib>
#include <pthread.h>
#include <string>
#include <functional>

namespace my_mutex
{
    class Mutex
    {
    public:
        Mutex()
        {
            pthread_mutex_init(&_mutex, nullptr);
        }
        void Lock()
        {
            pthread_mutex_lock(&_mutex);
        }
        void UnLock()
        {
            pthread_mutex_unlock(&_mutex);
        }
        ~Mutex()
        {
            pthread_mutex_destroy(&_mutex);
        }
        pthread_mutex_t *GetMutex()
        {
            return &_mutex;
        }

    private:
        pthread_mutex_t _mutex;
    };

    class MutexGuard
    {
    public:
        MutexGuard()
        {
            _mutex.Lock();
        }
        ~MutexGuard()
        {
            _mutex.UnLock();
        }

    private:
        Mutex _mutex;
    };
}